package client;

import java.net.*;
import java.io.*;

import shared.SerialData;
public class ATMTCPClient {
	
	public void runAtmClient(){
		
		
		
		
		
	// arguments supply message and hostname of destination
	Socket s = null;
	    try{
	    	int serverPort = 7896;
	   	s = new Socket("localhost", serverPort);    
	   	
	   	
		ByteArrayOutputStream fos = new ByteArrayOutputStream();
		
		ObjectInputStream in = new ObjectInputStream( s.getInputStream());
		
		ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
	   	
		SerialData sd = new SerialData();
		sd.userAccountNumber = 123;
		sd.userPin = 321;
		sd.userExist = false;
		
		//send to server
		System.out.println("Sending, user exists: " + sd.userExist);
		oos.writeObject(sd);
		
		// receive from server
		SerialData sdServer = (SerialData) in.readObject();
		// see what we got
		System.out.println("Received, user exists: "+ sdServer.userExist) ;      
       	    }catch (UnknownHostException e){
			System.out.println("Sock:"+e.getMessage()); 
	    }catch (EOFException e){System.out.println("EOF:"+e.getMessage());
    	    }catch (IOException e){System.out.println("IO:"+e.getMessage());
    	    } catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {if(s!=null) try {s.close();}catch (IOException e){System.out.println("close:"+e.getMessage());}}
  	}
}

